package com.FileDemo;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class BufferedOutputStreamDemo {
    public static void main(String[] args) throws IOException {
        //字节缓冲输出流
//        FileOutputStream fos = new FileOutputStream("fos.txt");
//        BufferedOutputStream bos = new BufferedOutputStream(fos);
//
//        bos.write("hello\r".getBytes(StandardCharsets.UTF_8));
//        bos.write("world\r".getBytes(StandardCharsets.UTF_8));
//
//        bos.close();
//        fos.close();

        //字节缓冲输入流
//        FileInputStream fis = new FileInputStream("fos.txt");
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("fos.txt"));

        //一次读取一个字节数据
        int by;
        while((by = bis.read())!=-1){
            System.out.print((char)by);
        }


        //一次读取一个字节数组数据
//        byte[] bytes = new byte[1024];
//        int len;
//        while ((len = bis.read(bytes)) != -1) {
//            System.out.println(len);
//            System.out.print(new String(bytes,0,len));
//        }

        bis.close();

    }
}
